package com.s4.controller;

import com.s4.entity.Product;
import com.s4.service.ProductService;
import com.s4.service.impl.ProductServiceImpl;
import com.sun.tracing.dtrace.ProviderAttributes;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @author XIAOLIANG
 * @ClassName test.java
 * @Description TODO
 * @createTime 2021年03月05日 19:55:00
 */
@Controller
public class test {
	ProductService productService =   new ProductServiceImpl();

	@ResponseBody
	@RequestMapping("/test")
	public String test(){
		return "test ok!";
	}

	@RequestMapping("/get/{id}")
	@ResponseBody
	public String getById(@PathVariable("id") Integer id, HttpServletResponse response){
		Product product = productService.selectOneById(id);
		System.out.println(product);

		response.setCharacterEncoding("utf-8");
		return product.toString();


	}


	@RequestMapping("/delete/{id}")
	@ResponseBody
	public String deleteById(@PathVariable("id") Integer id){
		boolean b = productService.deleteProduct(id);

		System.out.println(b);
		return String.valueOf(b);

	}

}
